package ui 
{
	import data.GCExperienceData;
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import ui.textfield.GCTextField;
	import flash.text.TextFieldAutoSize;
	/**
	 * ...
	 * @author Sterling Swigart
	 */
	public class GCExperienceBar extends Sprite
	{
		private static const redBarX:uint = 9;
		private static const redBarY:uint = 9;
		private static const redBarHeight:uint = 16;
		private static const redBarMaxWidth:uint = 280;
		
		private var xp:uint;
		private var lvl:uint;
		private var xpBar:Shape;
		private var lvlText:GCTextField;
		
		public function GCExperienceBar() 
		{
			xp = 0;
			lvl = 0;
			
			var bitmap:Bitmap = GCResources.getResource("experience_bar");
			addChild(bitmap);
			
			xpBar = new Shape();
			addChild(xpBar);
			
			lvlText = new GCTextField();
			lvlText.setXY(redBarX, redBarY - 2);
			lvlText.setDimensions(redBarMaxWidth, redBarHeight + 4);
			lvlText.setStyle(GCTextField.TEXT_TYPE_LEVEL);
			lvlText.textColor = 0xFFFFFF;
			lvlText.text = "Level 0";
			addChild(lvlText);
		}
		
		public function setXp(lvl:uint, newXp:uint):void
		{
			xp = newXp;
			var width:uint = xp * (redBarMaxWidth as Number) / GCExperienceData._experienceSequence[lvl];
			trace("Width of xp bar: " + width);
			xpBar.graphics.clear();
			xpBar.graphics.beginFill(0xFF0000);
			xpBar.graphics.drawRect(redBarX, redBarY, width, redBarHeight);
			
			if (this.lvl != lvl)
			{
				this.lvl = lvl;
				lvlText.text = "Level " + (lvl.toString());
			}
		}
	}

}